package org.NooLab.glue.net.http.rest.resources;



import org.NooLab.glue.net.http.rest.HttpRestletServer;
import org.NooLab.glue.net.http.rest.RestletBoxPropertiesIntf;
import org.NooLab.glue.net.http.rest.RestletMessageSinkIntf;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import org.restlet.security.ChallengeAuthenticator;



public class ResourceBindingForBoards extends ResourceBindingForClients {
	// this is abstracting from flavor = {SOURCE, RECEPTOR}

	Router router;
	
	public ResourceBindingForBoards( HttpRestletServer parent,
									  RestletBoxPropertiesIntf restletBoxProperties) {
		
		super(restletBoxProperties);
		messageSink = (RestletMessageSinkIntf)parent;
 		// this will be inferred through reflection in the primary message handler of Restlet
		
		// router = parent.getRouter() ;
	}

	 
	
	@Override
	public Restlet createInboundRoot() {

		ChallengeAuthenticator guard;
		
		Restlet returnedRestlet;

		// Create a router Restlet that defines routes.
		router = new Router(getContext());

		/*
		 * Router myRouter = (Router)this.getApplication.getRoot(); ?? 

		 * 
		 * these classes are created only UPON receiving a physical message 
		 */
		router.attach("/state/{clientid}", SourceStateResource.class);
		router.attach("/relay", DataRelayResource.class);
		router.attach("/data", DataRelayResource.class);
		router.attach("/register", RegistrationsResource.class);

		
		// dynamic routing using URI templates
		router.attach("/transaction/{transactionid}/state", StateResource.class);
		// in the respective resource handler (here: <StateResource>),
		// an object must exist
		// of EXACTLY that name (here: "transactionid") !!

		// this introduces the guard to a position before ANY of the items on
		// the path
		// it is purely optional
		if (useAuthentication) {
			guard = introduceAuthenticator(router);
			returnedRestlet = guard;
		} else {
			returnedRestlet = router;
		}
  
		
		return returnedRestlet;
	}

}
